<template>
    <h1>home</h1>
    <!-- <router-link to="/home/left">左</router-link>
    <router-link to="/home/right">右</router-link> -->
    <el-row>
        <el-col :span="4">
            <router-link :to="{ path: '/home/left', query: { id: classes[0].id } }">左yangyang</router-link>
        </el-col>
        <el-col :span="4">
            <router-link :to="{ name: 'right', params: { id: classes[1].id } }">右zhilong</router-link>
        </el-col>
    </el-row>
    <router-view></router-view>
</template>

<script lang="ts">
import { defineComponent, reactive } from "vue";
import { onBeforeRouteLeave } from "vue-router";

export default defineComponent({
    setup() {
        const classes = reactive([
            {
                id: "01",
                name: "洋洋",
                hobby: ["打游戏", "爱敲代码", "学习"],
            },
            {
                id: "02",
                name: "志龙",
                hobby: ["爱钱", "敲代码", "旅游"],
            },
        ]);
        //在setup里只有这个好用
        onBeforeRouteLeave(()=>{
            console.log("离开后");
            
        })
        return {
            classes,
        };
        //组件守卫写在setup外面，三个都能正常用
    },
});
</script>

<style scoped>

</style>